﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OLMS.DAL;
using OLMS.BLL;

namespace OLMS.Admin
{
    public partial class OrdersView : System.Web.UI.Page
    {      
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                OrderDetailBinder();
            }           
        }

        private void OrderDetailBinder()
        {
            int orderId = Convert.ToInt32(Request["oid"]);
            Orders order = OrderBLL.GetOrdersById(orderId);
            lblOrderDate.Text = string.Format("下单日期：{0:D}", order.OrderDate);
            lblUserName.Text+= order.Username;
            lblAddress.Text += order.Address;
            lblEmail.Text += order.Email;
            lblPhone.Text += order.Phone;
            lblPostalCode.Text += order.PostalCode;
            lblTotal.Text = string.Format("订单金额：{0:C}", order.Total);
            List<OrderDetails> list = OrderBLL.GetOrderDetailsByOrderId(orderId, 0);
            repOrderDetailList.DataSource = list.Select(od => new
            {
                OrderDetailId = od.OrderDetailId,
                OrderId = od.OrderId,
                AlbumId = od.AlbumId,
                Quantity = od.Quantity,
                UnitPrice = od.UnitPrice,
                AlbumName = AlbumBLL.GetAlbumsById(od.AlbumId).Title,
                ArtistName = AlbumBLL.GetAlbumsById(od.AlbumId).Artists.Name,
                TotalPrice = string.Format("{0:C}元", od.Quantity * od.UnitPrice)
            }).ToList(); ;
            repOrderDetailList.DataBind();
        }
       
        protected void btnReturn_Click(object sender, EventArgs e)
        {

            Response.Redirect("OrdersManager.aspx");
        }
    }
}